﻿using System;
using System.Reflection;
using UFIDA.U9.Base.Profile;
using UFIDA.U9.Base.Profile.Proxy;
using UFSoft.UBF.Util.Log;

namespace UFIDA.U9C.Cust.ZL.PlugBE.Tool
{
    public class PubWebClass
    {

        private static ILogger logger = LoggerManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 插件开启
        /// </summary>
        public static bool IsOpenPlug()
        {
            string ProfileCode = "Cust_IsOpenPlug";
            GetProfileValueProxy bpObj = new GetProfileValueProxy();
            bpObj.ProfileCode = ProfileCode;
            PVDTOData pVTDOData = bpObj.Do();
            bool isSync = false;
            if (pVTDOData == null || pVTDOData.ProfileValue == null)
            {
                return isSync;
            }
            isSync = (pVTDOData.ProfileValue == "1" || pVTDOData.ProfileValue.ToUpper() == "TRUE") ? true : false;
            return isSync;

        }
        #region  mes
        /// <summary>
        /// mes出货单新增接口
        /// </summary>
        public static string mes_ShipUrl = MESUrl() + "/openapi/mes/hq/outorderedit";
  

        /// <summary>
        /// 获取MES接口地址
        /// </summary>
        /// <returns></returns>
        public static string MESUrl()
        {
            string ProfileCode = "Cust_ZLMesURL";
            GetProfileValueProxy bpObj = new GetProfileValueProxy();
            bpObj.ProfileCode = ProfileCode;
            PVDTOData pVTDOData = bpObj.Do();
            if (pVTDOData == null || pVTDOData.ProfileValue == null)
            {
                throw new Exception("MES接口地址查询失败，请检查系统参数配置！");
            }
            return pVTDOData.ProfileValue;

        }


        #endregion

        #region srm

   
        #endregion


        // /缓存AccessToken
        // UFSoft.UBF.Util.Context.ThreadContext.CurrentContext.Add("AccessToken", accessToken);







        #region 写日志
        /// <summary>
        /// 写字符串日志
        /// </summary>
        /// <param name="msg">日志明细</param>
        public static void Log(string msg)
        {
            logger.Error(msg);
        }
        public static bool IsThrowNew()
        {
            return true;
        }

        /// <summary>
        /// 写对象日志
        /// </summary>
        /// <param name="msg">对象</param>
        public static void Log(string docType, string dataType, object msg, string result)
        {
            ILogger logger = null;
            string strType = "";
            string faultError = "";
            logger = LoggerManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            strType = docType + "---" + dataType;

            if (faultError == "")//成功
            {
                string text = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
                logger.Error(strType + "：成功\r\n" + result + "\r\n传输数据：-----------\r\n" + text);
                //logger.Error(Newtonsoft.Json.JsonConvert.SerializeObject(msg));
            }
            else
            {
                if (logger.IsErrorEnabled)
                {
                    string text = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
                    logger.Error(strType + "：失败\r\n" + result + "\r\n传输数据：-----------\r\n" + text);
                    if (IsThrowNew())
                        throw new Exception(strType + "：" + faultError);
                }
            }


        }



        #endregion


    }





}
